const emojis = [
  ["[微笑]", "emotion_weixiao.png"],
  ["[得意]", "emotion_deyi.png"],
  ["[害羞]", "emotion_haixiu.png"],
  ["[睡]", "emotion_shui.png"],
  ["[尴尬]", "emotion_ganga.png"],
  ["[发火]", "emotion_fanu.png"],
  ["[呲牙]", "emotion_ciya.png"],
  ["[惊讶]", "emotion_jingya.png"],
  ["[难过]", "emotion_nanguo.png"],
  ["[酷]", "emotion_ku.png"],
  ["[汗]", "emotion_lenghan.png"],
  ["[抓狂]", "emotion_zhuakuang.png"],
  ["[偷笑]", "emotion_touxiao.png"],
  ["[可爱]", "emotion_keai.png"],
  ["[白眼]", "emotion_baiyan.png"],
  ["[傲慢]", "emotion_aoman.png"],
  ["[饥饿]", "emotion_jie.png"],
  ["[惊恐]", "emotion_jingkong.png"],
  ["[流汗]", "emotion_liuhan.png"],
  ["[憨笑]", "emotion_hanxiao.png"],
  ["[大兵]", "emotion_dabing.png"],
  ["[奋斗]", "emotion_fendou.png"],
  ["[咒骂]", "emotion_zouma.png"],
  ["[疑问]", "emotion_yiwen.png"],
  ["[嘘]", "emotion_xu.png"],
  ["[晕]", "emotion_yun.png"],
  ["[折磨]", "emotion_fakuang.png"],
  ["[衰]", "emotion_shuai.png"],
  ["[骷髅]", "emotion_kulou.png"],
  ["[敲打]", "emotion_qiaoda.png"],
  ["[擦汗]", "emotion_cahan.png"],
  ["[左哼哼]", "emotion_zuohengheng.png"],
  ["[右哼哼]", "emotion_youhengheng.png"],
  ["[哈欠]", "emotion_haqian.png"],
  ["[鄙视]", "emotion_bishi.png"],
  ["[委屈]", "emotion_weiqu.png"],
  ["[快哭了]", "emotion_kuaikule.png"],
  ["[菜刀]", "emotion_caidao.png"],
  ["[西瓜]", "emotion_xigua.png"],
  ["[啤酒]", "emotion_pijiu.png"],
  ["[咖啡]", "emotion_kafei.png"],
  ["[饭]", "emotion_fan.png"],
  ["[凋谢]", "emotion_diaoxie.png"],
  ["[蛋糕]", "emotion_dangao.png"],
  ["[闪电]", "emotion_shandian.png"],
  ["[炸弹]", "emotion_zhadan.png"],
  ["[刀]", "emotion_dao.png"],
  ["[足球]", "emotion_zuqiu.png"],
  ["[瓢虫]", "emotion_pachong.png"],
  ["[便便]", "emotion_bianbian.png"],
  ["[月亮]", "emotion_yueliang.png"],
  ["[拥抱]", "emotion_baobao.png"],
  ["[握手]", "emotion_woshou.png"],
  ["[胜利]", "emotion_shengli.png"],
  ["[抱拳]", "emotion_baoquan.png"],
  ["[勾引]", "emotion_gouying.png"],
  ["[拳头]", "emotion_quantou.png"],
  ["[差劲]", "emotion_chajing.png"],
  ["[爱你]", "emotion_aini.png"],
  ["[NO]", "emotion_no.png"],
  ["[OK]", "emotion_ok.png"],
  ["[跳跳]", "emotion_tiaotiao.png"],
  ["[发抖]", "emotion_fadou.png"],
  ["[怄火]", "emotion_ouhuo.png"],
  ["[磕头]", "emotion_ketou.png"],
  ["[回头]", "emotion_huitou.png"],
  ["[激动]", "emotion_jidong.png"]
];

const emoji = {
  emojis: emojis,

  getEmojis: function() {
    return this.emojis;
  },
  getEmojiNames: function(index) {
    return this.emojis[index][0];
  },
  getEmojiSrc: function(index) {
    return "./static/images/emjon/" + this.emojis[index][1];
  },

  /**
   * emoji表情转img标签
   * @param content
   * @returns {*}
   */
  emoji_img: function(content) {
    var pattern1 = /\[[A-Za-z\u4e00-\u9fa5]+\]/g;
    var pattern2 = /\[[A-Za-z\u4e00-\u9fa5]+\]/;
    var contentArray = content.match(pattern1);
    var src;
    if (contentArray != null) {
      for (var i = 0; i < contentArray.length; i++) {
        for (var j = 0; j < this.emojis.length; j++) {
          if (contentArray[i] == this.emojis[j][0]) {
            src = '<img src="./static/images/emjon/' + this.emojis[j][1] + '">';
            break;
          }
        }
        if (src) {
          content = content.replace(pattern2, src);
        }
      }
    }
    return content;
  },

  img_emoji: function(content) {
    var pattern1 = /<img[^>]+>/g;
    var pattern2 = /<img[^>]+>/;
    var contentArray = content.match(pattern1);
    var src;
    if (contentArray != null) {
      for (var i = 0; i < contentArray.length; i++) {
        for (var j = 0; j < this.emojis.length; j++) {
          var img = contentArray[i];
          var filename =
            img.substring(img.lastIndexOf("/") + 1, img.lastIndexOf(".")) +
            ".png";
          if (filename == this.emojis[j][1]) {
            src = this.emojis[j][0];
            break;
          }
        }
        if (src) {
          content = content.replace(pattern2, src);
        }
      }
    }
    return content;
  }
};
export default emoji;
